package com.cqhilink.iot.jobstandardmanagement.services.innerservice.impl.employee;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cqhilink.api.common.utils.UniqueUtil;
import com.cqhilink.api.common.utils.date.DateStyle;
import com.cqhilink.api.common.utils.date.DateUtil;
import com.cqhilink.api.common.utils.enums.RespCodeEnum;
import com.cqhilink.iot.jobstandardmanagement.common.enums.BootstrapUtil;
import com.cqhilink.iot.jobstandardmanagement.common.enums.FileTypeUtil;
import com.cqhilink.iot.jobstandardmanagement.facade.service.permission.JsmRolesService;
import com.cqhilink.iot.jobstandardmanagement.facade.utils.OrganizationLevel;
import com.cqhilink.iot.jobstandardmanagement.facade.utils.TreeIconSkin;
import com.cqhilink.iot.jobstandardmanagement.dao.mapper.*;
import com.cqhilink.iot.jobstandardmanagement.facade.model.*;
import com.cqhilink.iot.jobstandardmanagement.facade.service.OutZtreeService;
import com.cqhilink.iot.jobstandardmanagement.facade.service.department.JsmDepartmentService;
import com.cqhilink.iot.jobstandardmanagement.facade.service.employee.JsmCertificateTypeService;
import com.cqhilink.iot.jobstandardmanagement.facade.service.employee.JsmEmployeeCertificateService;
import com.cqhilink.iot.jobstandardmanagement.facade.service.employee.JsmEmployeeService;
import com.cqhilink.iot.jobstandardmanagement.facade.service.file.JsmFileService;
import com.cqhilink.iot.jobstandardmanagement.facade.service.organization.JsmOrganizationService;
import com.cqhilink.iot.jobstandardmanagement.facade.service.post.JsmPostTypeService;
import com.cqhilink.iot.jobstandardmanagement.facade.service.teaminfo.JsmTeamInfoService;
import com.cqhilink.iot.jobstandardmanagement.facade.service.teaminfo.JsmTeamMembersService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;

/**
 * Created by zmling on 2016/11/22.
 * 人员信息
 */
public class JsmEmployeeServiceImpl implements JsmEmployeeService {
    public Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private DepartmentMapper departmentMapper;
    @Autowired
    private JsmCertificateTypeService jsmCertificateTypeService;
    @Autowired
    private JsmEmployeeCertificateService jsmEmployeeCertificateService;
    @Autowired
    private JsmFileService fileService;
    @Autowired
    private EmployeeCertificateMapper employeeCertificateMapper;
    @Autowired
    private FileMapper fileMapper;
    @Autowired
    private JsmOrganizationService organizationService;
    @Autowired
    private JsmDepartmentService departmentService;
    @Autowired
    private JsmTeamInfoService teamInfoService;
    @Autowired
    private JsmTeamMembersService jsmTeamMembersService;
    @Autowired
    private JsmPostTypeService jsmPostTypeService;
    @Autowired
    private OutZtreeService outZtreeService;
    // 查询角色
    @Autowired(required = false)
    private JsmRolesService rolesService;
    @Autowired(required = false)
    private OrganizationMapper organizationMapper ;

    /**
     * 新增
     *
     * @param employee            添加用户
     * @param employeeCertificate 添加人员证书
     * @param uploadFiles         上传头像
     * @param deletedFiles        删除头像
     * @param e                   登录用户所有信息
     * @throws Exception
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void employeeAdd(Employee employee, List<EmployeeCertificate> employeeCertificate, String uploadFiles, String deletedFiles, Employee e) throws Exception {
        if (employee != null) {
            Department param = departmentService.selectById(employee.getDepId());
            if (param != null) {
                employee.setOrgId(param.getParentOrgId());
            } else {
                employee.setOrgId(employee.getDepId());
                employee.setDepId(null);
            }
            String employeeId = UniqueUtil.uuid();
            employee.setEmployeeId(employeeId);
            employee.setCreatorId(e.getEmployeeId());
            employee.setModifierId(e.getEmployeeId());
            employee.setOperatorId(e.getEmployeeId());
            Date date = new Date();
            employee.setModifyTime(date);
            employee.setCreateTime(date);
            employee.setPassword("123456");
            //状态0是正常；1是删除
            employee.setStatus((short) 0);
//			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (null != employee.getEnrollDatets() && !"".equals(employee.getEnrollDatets())) {
//				employee.setEnrollDate(sdf.parse(employee.getEnrollDatets()));
                employee.setEnrollDate(DateUtil.StringToDate(employee.getEnrollDatets(), DateStyle.YYYY_MM_DD));
            }
            if (null != employee.getBirthdayts() && !"".equals(employee.getBirthdayts())) {
//				employee.setBirthday(sdf.parse(employee.getBirthdayts()));
                employee.setBirthday(DateUtil.StringToDate(employee.getBirthdayts(), DateStyle.YYYY_MM_DD));
            }
            employeeMapper.insertSelective(employee);
            //保存上传图像
            fileService.addFile(uploadFiles, deletedFiles, employeeId);
            //保存人员对应的证书信息
            if (employeeCertificate.size() > 0) {
                for (EmployeeCertificate emlcf : employeeCertificate) {
                    if (emlcf.getCardbookName() != null && emlcf.getCardbookName() != "") {
                        CertificateType certificateType = jsmCertificateTypeService.findCertificateType(emlcf.getCardbookName());
                        emlcf.setCertificateTypeId(certificateType.getCertificateTypeId());
                    }
                    emlcf.setEmployeeCertificateId(UniqueUtil.uuid());
                    emlcf.setEmployeeId(employeeId);
                    emlcf.setName(employee.getName());
                    emlcf.setCreateTime(new Date());
                    emlcf.setCreatorId(e.getEmployeeId());
                    emlcf.setModifierId(e.getEmployeeId());
                    emlcf.setModifyTime(new Date());
                    emlcf.setState(BigDecimal.valueOf(0));
                    jsmEmployeeCertificateService.addEmployeeCertificate(emlcf);
                    //保存证书信息对应的附件信息
                    if (emlcf.getUploadedFiles() != null) {
                        String uploadFiless = JSON.toJSONString(emlcf.getUploadedFiles());
                        fileService.addFile(uploadFiless, null, emlcf.getEmployeeCertificateId());
                    }
                }
            }
        }
    }

    /**
     * 查询列表
     *
     * @param employee
     * @return
     * @throws Exception
     */
    @Override
    public JSONObject findEmployeeList(EmployeeVo employee) throws Exception {
        JSONObject jsonObject = new JSONObject();
        if (null != employee.getEnrollDatets() && !"".equals(employee.getEnrollDatets())) {
            employee.setEnrollDate(DateUtil.StringToDate(employee.getEnrollDatets(), DateStyle.YYYY_MM_DD));
        }
        Department dep = departmentService.selectById(employee.getOrgId());
        if (dep != null) {
            employee.setOrgId(null);
            employee.setDepId(dep.getDepId());
        }
        employee.setLimit(employee.getLimit() == null ? 10 : employee.getLimit());
        employee.setOffset(employee.getOffset() == null ? 0 : employee.getOffset());
        employee.setFilterMap(BootstrapUtil.filterStringToMap(employee.getFilter()));
        if (employee.getSearch() != null && employee.getSearch() != "") {
            employee.setSearch(employee.getSearch().trim());
        }
        jsonObject.put("total", employeeMapper.queryCount(employee));
        List<EmployeeVo> list = employeeMapper.queryList(employee);
        jsonObject.put("rows", JSON.toJSON(list));
        return jsonObject;
    }

    /**
     * 根据主键查询人员信息
     *
     * @param employeeId
     * @return
     * @throws Exception
     */
    @Override
    public EmployeeVo findEmployeeById(String employeeId) throws Exception {
        EmployeeVo employee = employeeMapper.selectByPrimaryKey(employeeId);
        if (employee != null && employee.getDepName() == null && employee.getOrgName() != null) {
            employee.setDepName(employee.getOrgName());
        }
        if (employee != null && StringUtils.isNotEmpty(employee.getWorkSpeciesId())) {
            List<String> list = new ArrayList<String>(Arrays.asList(employee.getWorkSpeciesId().split(",")));
            PostType pt = new PostType();
            pt.setList(list);
            pt.setPostType((short) 2);
            List<PostType> ptList = jsmPostTypeService.selectByPostTypeId(pt);
            int i = 0;
            StringBuffer sb = new StringBuffer();
            for (PostType p : ptList) {
                if (i == 0) {
                    sb.append(p.getPosttypeName());
                    i = 1;
                } else {
                    sb.append("," + p.getPosttypeName());
                }
            }
            employee.setBirthdayts(sb.toString());
        }
        return employee;
    }

    /**
     * 修改
     *
     * @param employee            修改人员信息
     * @param employeeCertificate 修改人员证书
     * @param uploadFiles         上传头像
     * @param deletedFiles        删除头像
     * @param e                   登录人员信息
     * @throws Exception
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void employeeUpdate(Employee employee, List<EmployeeCertificate> employeeCertificate, String uploadFiles, String deletedFiles, Employee e) throws Exception {
        if (employee != null) {
            Department de = departmentMapper.selectById(employee.getDepId());
            if (de != null) {
                employee.setOrgId(de.getParentOrgId());
            } else {
                employee.setOrgId(employee.getDepId());
                employee.setDepId("");
            }
            employee.setModifyTime(new Date());
            if (employee.getEnrollDatets() != null && employee.getEnrollDatets() != "") {
                employee.setEnrollDate(DateUtil.StringToDate(employee.getEnrollDatets(), DateStyle.YYYY_MM_DD));
            }
            if (employee.getBirthdayts() != null && employee.getBirthdayts() != "") {
                employee.setBirthday(DateUtil.StringToDate(employee.getBirthdayts(), DateStyle.YYYY_MM_DD));
            }
            employee.setModifierId(e.getEmployeeId());
            employee.setModifyTime(new Date());
            employeeMapper.updateByPrimaryKeySelective(employee);

            //保存上传图像
            fileService.addDelFile(uploadFiles, employee.getEmployeeId());
            if (employeeCertificate.size() > 0) {
                for (EmployeeCertificate emlcf : employeeCertificate) {
                    if (emlcf.getCardbookName() != null && emlcf.getCardbookName() != "") {
                        CertificateType certificateType = jsmCertificateTypeService.findCertificateType(emlcf.getCardbookName());
                        emlcf.setCertificateTypeId(certificateType.getCertificateTypeId());
                    }
                    if (emlcf.getEmployeeCertificateId() != null && emlcf.getEmployeeCertificateId() != "") {
                        emlcf.setCreatorId(e.getEmployeeId());
                        jsmEmployeeCertificateService.updateEmployeeCertificate(emlcf);
                    } else {
                        emlcf.setEmployeeCertificateId(UniqueUtil.uuid());
                        emlcf.setEmployeeId(employee.getEmployeeId());
                        emlcf.setName(employee.getName());
                        emlcf.setCreateTime(new Date());
                        emlcf.setCreatorId(e.getEmployeeId());
                        emlcf.setModifierId(e.getEmployeeId());
                        emlcf.setModifyTime(new Date());
                        emlcf.setState(BigDecimal.valueOf(0));
                        jsmEmployeeCertificateService.addEmployeeCertificate(emlcf);
                    }
                    //保存证书信息对应的附件信息
                    String uploadFiless = null;
                    String deletedFiless = null;
                    if (emlcf.getDeletedFiles() != null) {
                        deletedFiless = JSON.toJSONString(emlcf.getDeletedFiles());
                    }
                    if (emlcf.getUploadedFiles() != null) {
                        uploadFiless = JSON.toJSONString(emlcf.getUploadedFiles());
                    }
                    fileService.updateFile(uploadFiless, deletedFiless, emlcf.getEmployeeCertificateId());
                }
            }
        }
    }

    /**
     * 删除
     *
     * @param employee
     * @return
     * @throws Exception
     */
    @Override
    public int deletEemployee(Map employee) throws Exception {
        //删除人员对应的证书信息
        for (Object v : employee.values()) {
            if (v != null && v != "") {
                EmployeeCertificateVo employeeCertificateVo = new EmployeeCertificateVo();
                employeeCertificateVo.setEmployeeId(v.toString());
                List<EmployeeCertificateVo> list = employeeCertificateMapper.queryList(employeeCertificateVo);
                for (EmployeeCertificateVo li : list) {
                    if (li != null) {
                        //删除证书对应的附件信息
                        fileMapper.delByBusinessId(li.getEmployeeCertificateId());
                    }
                }
            }
        }
        //删除人员证书
        employeeCertificateMapper.updateByemployee(employee);
        return employeeMapper.updateEemployee(employee);
    }

    /**
     * 查询
     *
     * @param employee
     * @return
     * @throws Exception
     */
    @Override
    public List<EmployeeVo> queryList(Employee employee) throws Exception {
        List<EmployeeVo> list = employeeMapper.selectEmployeeList(employee);
        return list;
    }

    /**
     * 查询所有，为外部提供接口
     *
     * @param employee
     * @return
     * @throws Exception
     */
    @Override
    public List<EmployeeVo> findEmployees(Employee employee) throws Exception {
        List<EmployeeVo> list = employeeMapper.findList(employee);
        return list;

    }


    @Override
    public List<EmployeeVo> queryEmployeeByRoleDept(Map selectMap) {
        return employeeMapper.queryEmployeeByRoleDept(selectMap);
    }

    /**
     * @param list
     * @Author 卢曼成
     * @Description 批量插入
     * @Date 2017/2/8 18:04
     */
    @Override
    public int insertList(List<Employee> list) {
        return employeeMapper.insertList(list);
    }

    /**
     * @param list
     * @Author 卢曼成
     * @Description 批量修改
     * @Date 2017/2/8 17:18
     */
    @Override
    public int updateList(List<Employee> list) {
        return employeeMapper.updateList(list);
    }

    /**
     * @param list
     * @Author 卢曼成
     * @Description 批量逻辑删除
     * @Date 2017/2/8 17:18
     */
    @Override
    public int deleteList(List<Employee> list) {
        return employeeMapper.deleteList(list);
    }

    /**
     * @param orgId
     * @param sync
     * @param openOrg
     * @param openDept
     * @param keyword
     * @return
     * @throws Exception
     */
    @Override
    public List<Ztree> loadEmployeeZtree(String orgId, boolean sync, boolean openOrg, boolean openDept, String keyword) throws Exception {
        List<Ztree> ztreeList = new ArrayList<>();


        //没有搜索条件
        if (StringUtils.isEmpty(keyword)) {
            //初始化加载组织部门树：同时挂人员
            if (sync) {
                if (StringUtils.isNotEmpty(orgId)) {
                    //查询当前组织
                    Organization organization = organizationService.findOrgById(orgId);
                    //查询当前组织的所有儿子组织：去掉管线pipeline和井口well，这个种组织下不能挂人
                    List<Organization> orgList = organizationService.queryNodeWithoutPipelineWellByOrgId(orgId);
                    //当前组织和儿子组织：加入人员树
                    orgList.add(organization);
                    List<Ztree> orgZtreeList = organizationService.setZtree(orgList);
                    //重新设置isParent
                    for (Ztree orgZt : orgZtreeList) {
                        setOrgZtreeIsParent(orgZt, orgZt.getId());
                    }
                    ztreeList.addAll(orgZtreeList);

                    //当前组织下的人员加入人员树
                    Employee employee = new Employee();
                    employee.setOrgId(orgId);
                    List<Employee> orgEmployees = employeeMapper.selectListEmploye(employee);
                    //组织下面挂的人员：只有组织ID，不能有部门ID
                    if (orgEmployees != null) {
                        for (Employee emp : orgEmployees) {
                            if (!StringUtils.isEmpty(emp.getOrgId()) && StringUtils.isEmpty(emp.getDepId())) {
                                Ztree ztree = new Ztree();
                                ztree.setId(emp.getEmployeeId());
                                ztree.setName(emp.getName());
                                ztree.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                                ztree.setOpen(true);
                                ztree.setpId(emp.getOrgId());
                                ztreeList.add(ztree);
                            }
                        }
                    }

                    //查询当前组织下的部门
                    List<Ztree> depZtrelList = departmentService.getDeptZtreeByOrgId(orgId);
                    if (depZtrelList != null) {
                        for (Ztree depZt : depZtrelList) {
                            //组织下的部门加入人员树
                            setDepZtreeIsParent(depZt, depZt.getId());
                            ztreeList.add(depZt);
                        }
                    }
                }
                //异步加载后代组织和部门及其下面挂的人员
            } else {
                if (!StringUtils.isEmpty(orgId)) {
                    //根据组织机构Id , 加载出组织机构中的人员信息
                    Employee employee = new Employee();

                    if (openOrg) {
                        //查询当前组织的所有儿子组织：排除管线和井口
                        List<Organization> orgList = organizationService.queryNodeWithoutPipelineWellByOrgId(orgId);
                        List<Ztree> orgZtreeList = organizationService.setZtree(orgList);
                        //重新设置isParent
                        for (Ztree orgZt : orgZtreeList) {
                            setOrgZtreeIsParent(orgZt, orgZt.getId());
                        }
                        ztreeList.addAll(orgZtreeList);

                        //查询当前组织下的儿子部门
                        List<Ztree> depZtreelList = departmentService.getDeptZtreeByOrgId(orgId);
                        if (depZtreelList != null) {
                            for (Ztree depZt : depZtreelList) {
                                //组织下的部门加入人员树
                                setDepZtreeIsParent(depZt, depZt.getId());
                                ztreeList.add(depZt);
                            }
                        }

                        //查询当前组织下人员
                        employee.setOrgId(orgId);
                        List<Employee> orgEmployees = employeeMapper.selectListEmploye(employee);
                        //组织下面挂的人员：只有组织ID，不能有部门ID
                        if (orgEmployees != null) {
                            for (Employee emp : orgEmployees) {
                                if (!StringUtils.isEmpty(emp.getOrgId()) && StringUtils.isEmpty(emp.getDepId())) {
                                    Ztree ztree = new Ztree();
                                    ztree.setId(emp.getEmployeeId());
                                    ztree.setName(emp.getName());
                                    ztree.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                                    ztree.setOpen(true);
                                    ztree.setpId(emp.getOrgId());
                                    ztreeList.add(ztree);
                                }
                            }
                        }
                    }

                    if (openDept) {
                        //查询当前部门下的儿子部门
                        List<Ztree> depZtrelList = departmentService.queryDeptTreeByPDId(orgId);
                        if (depZtrelList != null) {
                            for (Ztree depZt : depZtrelList) {
                                //部门下的部门加入人员树
                                setDepZtreeIsParent(depZt, depZt.getId());
                                ztreeList.add(depZt);
                            }
                        }

                        //查询当前部门下的人员
                        employee.setDepId(orgId);
                        List<Employee> deptEmployees = employeeMapper.selectListEmploye(employee);
                        //部门下挂的人员：既有组织ID，又有部门ID
                        if (deptEmployees != null) {
                            for (Employee emp : deptEmployees) {
                                if (!StringUtils.isEmpty(emp.getOrgId()) && !StringUtils.isEmpty(emp.getDepId())) {
                                    Ztree ztree = new Ztree();
                                    ztree.setId(emp.getEmployeeId());
                                    ztree.setName(emp.getName());
                                    ztree.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                                    ztree.setOpen(true);
                                    ztree.setpId(emp.getDepId());
                                    ztreeList.add(ztree);
                                }

                            }
                        }
                    }
                }
            }
            //有搜索条件
        } else {
            //初始化加载组织部门树：同时挂人员
            if (sync) {
                List<Ztree> totalZtreeList = this.getEmployeeMixedZtreeByOrgId(orgId);

                outZtreeService.removeDuplicate(totalZtreeList);

                if (totalZtreeList != null && totalZtreeList.size() > 0) {
                    //查询包含搜索字符的节点：并加入结果树
                    List<Ztree> targetNodeList = new ArrayList<>();
                    for (Ztree ztree : totalZtreeList) {
                        if (ztree.getName() != null) {
                            if (ztree.getName().toLowerCase().contains(keyword.toLowerCase())) {
                                targetNodeList.add(ztree);
                            }
                        }
                    }
                    ztreeList.addAll(targetNodeList);

                    //查询包含搜索字符的节点的祖先节点：并加入结果树
                    for (Ztree ztree : targetNodeList) {
                        List tempZtreeList = new ArrayList<>();
                        //递归查找祖先节点：不包括自身
                        outZtreeService.getAncestorNodeList(ztree, totalZtreeList, tempZtreeList);
                        ztreeList.addAll(tempZtreeList);
                    }

                    //必须去除：因为不同的目标节点可以有共通的父节点
                    outZtreeService.removeDuplicate(ztreeList);
                }
                //异步加载后代组织和部门及其下面挂的人员
            } else {
                if (!StringUtils.isEmpty(orgId)) {
                    //根据组织机构Id , 加载出组织机构中的人员信息
                    Employee employee = new Employee();

                    if (openOrg) {
                        //查询当前组织的所有儿子组织
                        List<Organization> orgList = organizationService.queryNodeWithoutPipelineWellByOrgId(orgId);
                        List<Ztree> orgZtreeList = organizationService.setZtree(orgList);
                        //重新设置isParent
                        for (Ztree orgZt : orgZtreeList) {
                            setOrgZtreeIsParent(orgZt, orgZt.getId());
                        }
                        ztreeList.addAll(orgZtreeList);

                        //查询当前组织下的儿子部门
                        List<Ztree> depZtreelList = departmentService.getDeptZtreeByOrgId(orgId);
                        if (depZtreelList != null) {
                            for (Ztree depZt : depZtreelList) {
                                //组织下的部门加入人员树
                                setDepZtreeIsParent(depZt, depZt.getId());
                                ztreeList.add(depZt);
                            }
                        }

                        //查询当前组织下人员
                        employee.setOrgId(orgId);
                        List<Employee> orgEmployees = employeeMapper.selectListEmploye(employee);
                        //组织下面挂的人员：只有组织ID，不能有部门ID
                        if (orgEmployees != null) {
                            for (Employee emp : orgEmployees) {
                                if (!StringUtils.isEmpty(emp.getOrgId()) && StringUtils.isEmpty(emp.getDepId())) {
                                    Ztree ztree = new Ztree();
                                    ztree.setId(emp.getEmployeeId());
                                    ztree.setName(emp.getName());
                                    ztree.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                                    ztree.setOpen(true);
                                    ztree.setpId(emp.getOrgId());
                                    ztreeList.add(ztree);
                                }
                            }
                        }
                    }

                    if (openDept) {
                        //查询当前部门下的儿子部门
                        List<Ztree> depZtrelList = departmentService.queryDeptTreeByPDId(orgId);
                        if (depZtrelList != null) {
                            for (Ztree depZt : depZtrelList) {
                                //部门下的部门加入人员树
                                setDepZtreeIsParent(depZt, depZt.getId());
                                ztreeList.add(depZt);
                            }
                        }

                        //查询当前部门下的人员
                        employee.setDepId(orgId);
                        List<Employee> deptEmployees = employeeMapper.selectListEmploye(employee);
                        //部门下挂的人员：既有组织ID，又有部门ID
                        if (deptEmployees != null) {
                            for (Employee emp : deptEmployees) {
                                if (!StringUtils.isEmpty(emp.getOrgId()) && !StringUtils.isEmpty(emp.getDepId())) {
                                    Ztree ztree = new Ztree();
                                    ztree.setId(emp.getEmployeeId());
                                    ztree.setName(emp.getName());
                                    ztree.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                                    ztree.setOpen(true);
                                    ztree.setpId(emp.getDepId());
                                    ztreeList.add(ztree);
                                }

                            }
                        }
                    }
                }
            }
        }

        return ztreeList;
    }

    /**
     * 获取指定组织下的所有后代组织、后代部门、后代人员的混合树
     *
     * @param orgId
     * @return
     */
    public List<Ztree> getEmployeeMixedZtreeByOrgId(String orgId) throws Exception {
        List<Ztree> ztreeList = new ArrayList<>();
        if (StringUtils.isNotEmpty(orgId)) {
            //查询当前组织
            Organization organization = organizationService.findOrgById(orgId);
            //当前登录人的组织下的人员加入人员树：包括当前组织的后代部门的人员
            Employee employee = new Employee();
            employee.setOrgId(orgId);
            List<Employee> orgEmployees = employeeMapper.selectListEmploye(employee);
            //组织下面挂的后代人员：有可能挂在组织下，也可能挂在组织的部门下
            if (orgEmployees != null) {
                for (Employee emp : orgEmployees) {
                    Ztree ztree = new Ztree();
                    ztree.setId(emp.getEmployeeId());
                    ztree.setName(emp.getName());
                    ztree.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                    ztree.setOpen(true);
                    if (StringUtils.isNotEmpty(emp.getOrgId()) && StringUtils.isEmpty(emp.getDepId())) {
                        ztree.setpId(emp.getOrgId());
                    } else if (StringUtils.isNotEmpty(emp.getOrgId()) && StringUtils.isNotEmpty(emp.getDepId())) {
                        ztree.setpId(emp.getDepId());
                    }

                    ztreeList.add(ztree);
                }
            }

            //树查询自身及后代节点：向下遍历
            List<Organization> orgList = organizationService.selectDownByTreeWithoutPipelineWell(orgId);
            List<Ztree> orgZtreeList = organizationService.setZtree(orgList);
            //重新设置isParent
            for (Ztree orgZt : orgZtreeList) {
                setOrgZtreeIsParent(orgZt, orgZt.getId());
            }
            ztreeList.addAll(orgZtreeList);

            for (Organization org : orgList) {
                //所有组织下的后代部门加入人员树
                List<Ztree> depZtreelList = departmentService.getDeptZtreeByOrgId(org.getOrgId());
                if (depZtreelList != null) {
                    for (Ztree depZt : depZtreelList) {
                        //组织下的部门加入人员树
                        setDepZtreeIsParent(depZt, depZt.getId());
                        ztreeList.add(depZt);
                    }
                }

                //当前组织下的人员加入人员树：包括当前组织的后代部门的人员
                employee.setOrgId(org.getOrgId());
                orgEmployees = employeeMapper.selectListEmploye(employee);
                //组织下面挂的人员：只有组织ID，不能有部门ID
                if (orgEmployees != null) {
                    for (Employee emp : orgEmployees) {
                        Ztree ztree = new Ztree();
                        ztree.setId(emp.getEmployeeId());
                        ztree.setName(emp.getName());
                        ztree.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                        ztree.setOpen(true);
                        if (StringUtils.isNotEmpty(emp.getOrgId()) && StringUtils.isEmpty(emp.getDepId())) {
                            ztree.setpId(emp.getOrgId());
                        } else if (StringUtils.isNotEmpty(emp.getOrgId()) && StringUtils.isNotEmpty(emp.getDepId())) {
                            ztree.setpId(emp.getDepId());
                        }

                        ztreeList.add(ztree);
                    }
                }

            }

            return ztreeList;
        } else {
            return null;
        }
    }

    /**
     * 人员混合树的设置组织的ztree的isParent
     *
     * @param ztree
     * @param orgId
     * @throws Exception
     */
    public void setOrgZtreeIsParent(Ztree ztree, String orgId) throws Exception {
        //查询当前组织的所有儿子组织
        List<Organization> orgList = organizationService.queryNodeWithoutPipelineWellByOrgId(orgId);
        //查询当前组织下的部门
        List<Ztree> depZtreelList = departmentService.getDeptZtreeByOrgId(orgId);
        //查询当前组织下人员
        Employee employee = new Employee();
        employee.setOrgId(orgId);
        List<Employee> orgEmployees = employeeMapper.selectListEmploye(employee);
        if ((orgList != null && orgList.size() > 0) || (depZtreelList != null && depZtreelList.size() > 0) || (orgEmployees != null && orgEmployees.size() > 0)) {
            ztree.setIsParent(true);
        } else {
            ztree.setIsParent(false);
        }
    }

    /**
     * @param ztree
     * @param depId
     * @throws Exception
     */
    @Override
    public void setDepZtreeIsParent(Ztree ztree, String depId) throws Exception {
        List<DepartmentVO> sonDepList = departmentMapper.selectByPDId(depId);
        //查询当前部门下的人员
        Employee employee = new Employee();
        employee.setDepId(depId);
        List<Employee> deptEmployees = employeeMapper.selectListEmploye(employee);

        if ((sonDepList != null && sonDepList.size() > 0) || (deptEmployees != null && deptEmployees.size() > 0)) {
            ztree.setIsParent(true);
        } else {
            ztree.setIsParent(false);
        }
    }


    /**
     * @param orgId               组织机构Id
     * @param isLoadOrg           是否加载组织
     * @param isLoadDept          是否加载部门
     * @param isLoadOrgEmployee   加载机构下面的人
     * @param isALoadDeptEmployee 加载部门下的人
     * @param maxLevel            显示组织的最大层级
     * @param lessLevel           显示组织的最小层级
     * @param keyword             搜索值
     */
    @Override
    public List<Ztree> loadEmployeeZtree(String orgId, boolean isLoadOrg, boolean isLoadDept, boolean isLoadOrgEmployee, boolean isALoadDeptEmployee, String maxLevel, String lessLevel, String keyword) throws Exception {
        // 组织机构非空判断问题！
        return null;
    }

    /**
     * @Author 卢曼成
     * @Description 根据org查询该节点人员
     * @Date 2017/3/11 17:01
     */
    @Override
    public List<Ztree> loadEmployeeZtree(String orgId) throws Exception {
        List<Ztree> list = new ArrayList<Ztree>();
        if (orgId != null) {
            Organization param = organizationService.selectOrgByOrgId(orgId);
            Ztree ztree = new Ztree();
            if (param != null) {
                ztree.setId(param.getOrgId());
                ztree.setName(param.getOrgName());
                ztree.setIconSkin(TreeIconSkin.ICON_OA.getDesc());
            }
            Employee employee = new Employee();
            employee.setOrgId(orgId);
            List<Employee> employeeList = employeeMapper.selectListEmploye(employee);
            if (employeeList != null) {
                List<TeamInfo> tiList = teamInfoService.selectTeamInfos();
                List<TeamMembers> tmList = jsmTeamMembersService.selectByParamList(null);
                ztree.setOpen(true);
                list.add(ztree);
                for (Employee emp : employeeList) {
                    if (isEmployeeId(tiList, tmList, emp.getEmployeeId())) {
                        continue;
                    }
                    ztree = new Ztree();
                    ztree.setId(emp.getEmployeeId());
                    ztree.setName(emp.getName());
                    ztree.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                    ztree.setOpen(true);
                    ztree.setpId(emp.getOrgId());
                    list.add(ztree);
                }
            } else {
                list.add(ztree);
            }
        }
        return list;
    }

    /**
     * 判断负责是否存在
     *
     * @param tiList
     * @param employeeId
     * @return
     */
    private boolean isEmployeeId(List<TeamInfo> tiList, List<TeamMembers> tmList, String employeeId) {
        if (tiList != null && tiList.size() > 0) {
            Iterator<TeamInfo> it = tiList.iterator();
            while (it.hasNext()) {
                TeamInfo ti = it.next();
                if (employeeId.equals(ti.getEmployeeId())) {
                    return true;
                }
            }
        }
        if (tmList != null && tmList.size() > 0) {
            Iterator<TeamMembers> it = tmList.iterator();
            while (it.hasNext()) {
                TeamMembers ti = it.next();
                if (employeeId.equals(ti.getEmployeeId())) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * @param employeeId
     * @return Employee
     * @Author 卢曼成
     * @Description 根据ID查询
     * @CreateDateTime 2017/3/15 14:53
     **/
    public Employee queryByKeyId(String employeeId) {
        return employeeMapper.queryByKeyId(employeeId);
    }

    /**
     * @param list
     * @return List<String>
     * @Author 卢曼成
     * @Description 根据ID查询数据是否存在
     */
    @Override
    public List<String> selectByListId(List<Employee> list) {
        return employeeMapper.selectByListId(list);
    }

    /**
     * @param list
     * @return List<String>
     * @Author 卢曼成
     * @Description 根据postId获取关联的用户数量
     */
    @Override
    public int selectByPostCount(List<String> list) {
        return employeeMapper.selectByPostCount(list);
    }

    /**
     * @param employee 根据条件查询 人员信息 { 主要用于组织查询人 和 部门查询人信息 }
     */
    @Override
    public List<Employee> selectListEmploye(Employee employee) {
        return employeeMapper.selectListEmploye(employee);
    }

    /**
     * @param employeeId
     * @param email
     * @return boolean
     * @Author 卢曼成
     * @Description 验证邮箱是否重复
     */
    @Override
    public boolean isExisEmail(String employeeId, String email) {
        Employee employee = new Employee();
        employee.setEmployeeId(employeeId);
        employee.setEmail(email);
        int num = employeeMapper.isExis(employee);
        return num > 0 ? false : true;
    }

    /**
     * @param employeeId
     * @param loginId
     * @return boolean
     * @Author 卢曼成
     * @Description 验证用户名是否重复
     */
    @Override
    public boolean isExisLogId(String employeeId, String loginId) {
        Employee employee = new Employee();
        employee.setEmployeeId(employeeId);
        employee.setLoginId(loginId);
        int num = employeeMapper.isExis(employee);
        return num > 0 ? false : true;
    }

    /**
     * @param employeeId
     * @param workNumber
     * @return boolean
     * @Author 卢曼成
     * @Description 验证用户工号是否重复
     */
    @Override
    public boolean isWorkNumber(String employeeId, String workNumber) {
        Employee employee = new Employee();
        employee.setWorkNumber(workNumber);
        employee.setEmployeeId(employeeId);
        int num = employeeMapper.isExis(employee);
        return num > 0 ? false : true;
    }

    /**
     * @param orgId  组织机构id 或者部门id
     * @param roleId 当前选中角色
     * @return 根据组织机构 和 部门返回当前组织机构下 和  当前组织机构下有人员的组织机构 ， 进行问题查询 ， 进行数据数据组合
     * @throws Exception
     */
    @Override
    public List<PermissionErModel> loadEmployeeByOrgsOrDept(String orgId, String roleId) throws Exception {
        List<PermissionErModel> permissionErModels = new ArrayList<>();
        Map parMap = new HashMap<>();
        parMap.put("orgId", orgId);
        parMap.put("roleId", roleId);
        /**
         *  查询是否是部门
         */
        Organization organization = organizationService.selectOrgByOrgId(orgId);
        if (organization != null && organization.getOrgId() != null) {
            // 查询当前组织机构下的组织机构 和  当前组织机构下的组织部门， 并进行拼装
            permissionErModels = employeeMapper.selectEmployeeByRoleAndOrg(parMap);
        } else {
            // 查询部门
            permissionErModels = employeeMapper.selectEmployeeByRoleAndDept(parMap);
        }
        return permissionErModels;
    }

    /**
     * @param employeeVo 当前登录人
     * @param rolesName  角色名称
     */
    @Override
    public List<Employee> getEmployeeListByRole(EmployeeVo employeeVo, String rolesName) throws Exception {
        List<Employee> employeeList = new ArrayList<>();
        List<Organization> organizationList = organizationService.getOrganizationList(employeeVo);
        if (organizationList != null && organizationList.size() == 1 && StringUtils.isNotEmpty(rolesName)) {
            Roles roles = new Roles();
            roles.setRoleName(rolesName);
            roles.setOrgId(organizationList.get(0).getOrgId());
            //如果角色roles是部门负责人：查询本作业区下的所有部门负责人
            employeeList = employeeMapper.getEmployeeListByRole(roles);
        }
        return employeeList;
    }

    /**
     * @param employeeVo 当前登录人 ，
     * @param rolesName  角色名称[部门负责人,主管领导,分管领导]
     */
    @Override
    public List<Ztree> queryEmployeeZtree(EmployeeVo employeeVo, String rolesName) throws Exception {
        /**
         * [部门负责人,主管领导,分管领导]
         * 1：当为部门负责人的时候，则需要查询配置部门 查询当前部门负责人
         */
        logger.info("queryEmployeeZtree--->employeeVo=" + JSON.toJSONString(employeeVo) + "-->rolesName=" + rolesName);
        List<Ztree> ztreeList = new ArrayList<>();
        if (StringUtils.isNotEmpty(rolesName)) {
            List<Ztree> repeatList = new ArrayList<>();
            String[] roleArray = rolesName.split("，"); // 拆成多个角色分组
            //角色拆分，将角色拆分成多个角色，并进行设置数据 ;
            for (int roleInt = 0; roleInt < roleArray.length; roleInt++) {
                //设置角色问题
                //查询部门负责人：是查当前登录人所属部门的部门负责人，而不是所有部门的负责人
                if (StringUtils.isNotEmpty(roleArray[roleInt]) && roleArray[roleInt].equals("部门负责人")) {
                    Roles roles = new Roles();
                    roles.setRoleName(roleArray[roleInt]);
                    roles.setOrgId(employeeVo.getDepId());
                    // 获取当前操作问题 ;
                    List<EmployeeVo> employeeDeptList = employeeMapper.getEmployeeListSpecialByRole(roles);
                    repeatList.addAll(this.offSetZtree(employeeDeptList, roles));
                } else {
                    Roles roles = new Roles();
                    roles.setRoleName(roleArray[roleInt]);
                    roles.setOrgId(employeeVo.getOrgId());
                    List<EmployeeVo> employeeOrgList = employeeMapper.getEmployeeVoListByRole(roles);
                    repeatList.addAll(this.offSetZtree(employeeOrgList, roles));
                }
            }

            //代码修改后
            if(repeatList != null && repeatList.size() > 0){
                Map<String,String> noRepeatMap = new HashMap<>();
                for(Ztree z: repeatList){
                    //判断是否存在：排除id和pId为null的
                    if(StringUtils.isNotEmpty(z.getId()) && StringUtils.isNotEmpty(z.getpId())){
                        //过滤重复的组织或人员
                        if(StringUtils.isEmpty(noRepeatMap.get(z.getId()+z.getpId()))){
                            ztreeList.add(z);
                        }
                        noRepeatMap.put(z.getId()+z.getpId(),z.getId()+z.getpId());
                    }
                }
            }
        } else {
            return ztreeList;
        }

        logger.info("ztreeList--->ztreeList=" + JSON.toJSONString(ztreeList));
        return ztreeList;
    }


    @Override
    public List<EmployeeVo> queryEmployeeList(EmployeeVo employeeVo, String rolesName) throws Exception {
        /**
         * [部门负责人,主管领导,分管领导]
         * 1：当为部门负责人的时候，则需要查询配置部门 查询当前部门负责人
         */
        logger.info("queryEmployeeZtree--->employeeVo=" + JSON.toJSONString(employeeVo) + "-->rolesName=" + rolesName);
        List<EmployeeVo> employeeVoList = new ArrayList<>();
        if (StringUtils.isNotEmpty(rolesName)) {
            String[] roleArray = rolesName.split("，"); // 拆成多个角色分组
            //角色拆分，将角色拆分成多个角色，并进行设置数据 ;
            for (int roleInt = 0; roleInt < roleArray.length; roleInt++) {
                // 设置 角色问题
                if (StringUtils.isNotEmpty(roleArray[roleInt]) && roleArray[roleInt].equals("部门负责人")) {
                    Roles roles = new Roles();
                    roles.setRoleName(roleArray[roleInt]);
                    roles.setOrgId(employeeVo.getDepId());
                    // 获取当前操作问题 ;
                    List<EmployeeVo> employeeDeptList = employeeMapper.getEmployeeListSpecialByRole(roles);
                    employeeVoList.addAll(employeeDeptList);
                } else {
                    Roles roles = new Roles();
                    roles.setRoleName(roleArray[roleInt]);
                    roles.setOrgId(employeeVo.getOrgId());
                    List<EmployeeVo> employeeOrgList = employeeMapper.getEmployeeVoListByRole(roles);
                    employeeVoList.addAll(employeeOrgList);
                }
                // 判断是否有部门
            }
        } else {
            return employeeVoList;
        }

        logger.info("ztreeList--->ztreeList=" + JSON.toJSONString(employeeVoList));
        return employeeVoList;
    }

    /**
     * 将查询出来的人组织成角色人员树形结构
     */
    private List<Ztree> offSetZtree(List<EmployeeVo> employeeVoList, Roles roles) {
        Map<String,String>  orgMap = new HashMap<>();        //  部门组织
        Map<String,String>  roleInfoMap = new HashMap<>();   //  角色集合
        List<Ztree> ztreeList = new ArrayList<>();
        if (employeeVoList != null && employeeVoList.size() > 0) {
            for (EmployeeVo employeeVo : employeeVoList) {
                roleInfoMap.put(employeeVo.getRoleId(),employeeVo.getRoleName());
                Ztree ztree = new Ztree();
                ztree.setId(employeeVo.getEmployeeId());
                ztree.setName(employeeVo.getName());
                ztree.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                ztree.setpId(employeeVo.getRoleId());
                ztree.setOpen(true);
                ztree.setIsParent(false);
                ztreeList.add(ztree);
            }

            // 遍历角色，之后进行处理
            if(roleInfoMap != null && roleInfoMap.size() > 0){
                for (String roleId : roleInfoMap.keySet()) {
                    Ztree ztree = new Ztree();
                    ztree.setId(roleId);
                    ztree.setName(roleInfoMap.get(roleId));
                    ztree.setIconSkin(TreeIconSkin.ICON_ROLES.getDesc());
                    ztree.setOpen(true);
                    ztree.setIsParent(false);
                    ztreeList.add(ztree);
                    try {
                        Roles roles1 = rolesService.rolesSelect(roleId);
                        orgMap.put(roles1.getOrgId(),roles1.getOrgId());
                        ztree.setpId(roles1.getOrgId());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
            }
            // 遍历部门
            if(orgMap !=null && orgMap.size() > 0){
                for (String orgId : orgMap.keySet()) {
                    Ztree org = new Ztree();
                    Organization organization = organizationMapper.selectByPrimaryKey(orgId);
                    DepartmentVO departmentVO = departmentMapper.selectByDeptId(orgId);
                    if(departmentVO != null && StringUtils.isNotEmpty(departmentVO.getDepId())){
                        org.setId(departmentVO.getDepId());
                        org.setName(departmentVO.getDepName());
                        org.setIconSkin(TreeIconSkin.ICON_DEPT.getDesc());
                        org.setpId(departmentVO.getParentOrgId());
                    //必须做非空判断：如果专业技术岗组织被删除，则会报空指针异常，程序退出，无法查到下一步处理人
                    }else if(organization != null){
                        org.setId(organization.getOrgId());
                        org.setName(organization.getOrgName());
                        try {
                            org.setIconSkin(organizationService.offsetIconSkin(organization));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        org.setpId(organization.getParentOrgId());
                    }
                    org.setOpen(true);
                    org.setIsParent(false);
                    ztreeList.add(org);
                }
            }
        } else {
            Ztree ztree = new Ztree();
            ztree.setId(UniqueUtil.uuid());
            ztree.setName(roles.getRoleName());
            ztree.setIconSkin(TreeIconSkin.ICON_ROLES.getDesc());
            ztree.setpId("#");
            ztree.setOpen(true);
            ztree.setIsParent(false);
            ztreeList.add(ztree);
        }
        return ztreeList;
    }


    /**
     * 批量修改用户组织部门
     *
     * @param employeeVo
     * @return
     */
    @Override
    public int editOrg(EmployeeVo employeeVo) {
        List<String> list = JSONObject.parseArray(employeeVo.getCreatorId(), String.class);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("list", list);
        map.put("orgId", employeeVo.getOrgId());
        map.put("depId", employeeVo.getDepId());
        map.put("pOrgId", employeeVo.getOrgName());
        map.put("modifierId", employeeVo.getOrgName());
        map.put("modifyTime", new Date());
        return employeeMapper.editOrg(map);
    }

    /**
     * 查询组织部门人员树形
     *
     * @param orgId
     * @param pOrgId
     * @param keyword
     * @return
     * @throws Exception
     */
    @Override
    public List<Ztree> initUserZtree(String iconSkin, String orgId, String pOrgId, String keyword) throws Exception {
        if (StringUtils.isEmpty(orgId) && StringUtils.isEmpty(pOrgId) && StringUtils.isEmpty(keyword)) {
            return null;
        }
        if (StringUtils.isEmpty(pOrgId)) {
            String orgIds = organizationService.getUserOrgId(orgId);
            if (StringUtils.isNotEmpty(orgIds)) {
                orgId = orgIds;
            }
        } else {
            orgId = pOrgId;
        }
        List<Ztree> list = new ArrayList<>();
        if (StringUtils.isEmpty(keyword)) {
            if (StringUtils.isEmpty(iconSkin)) {
                //初始化
                list.addAll(this.loadEmployeeZtree(orgId, true, false, false, keyword));
            } else {
                //点击+号：展开异步
                //展开组织
                if (!iconSkin.equals("department")) {
                    list.addAll(this.loadEmployeeZtree(orgId, false, true, false, keyword));
                    //展开部门
                } else {
                    list.addAll(this.loadEmployeeZtree(orgId, false, false, true, keyword));
                }
            }
        } else {
            if (StringUtils.isEmpty(iconSkin)) {
                //初始化
                list.addAll(this.loadEmployeeZtree(orgId, true, false, false, keyword));
            } else {
                //点击+号：展开异步
                //展开组织
                if (!iconSkin.equals("department")) {
                    list.addAll(this.loadEmployeeZtree(orgId, false, true, false, keyword));
                    //展开部门
                } else {
                    list.addAll(this.loadEmployeeZtree(orgId, false, false, true, keyword));
                }
            }
        }
        return list;
    }

    /**
     * 根据ID集合查询数据
     *
     * @param list
     * @return
     */
    @Override
    public List<Employee> selectByKeyList(List<String> list) {
        if (list == null || list.size() == 0) {
            return null;
        }
        return employeeMapper.selectByKeyList(list);
    }

    /**
     * Excel导入用户信息
     *
     * @param evList 导入的Excel数据集合
     * @param orgId  导入人所属组织
     * @param userId 导入人ID
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Map<String, Object> importExcelUser(List<Employee> evList, String orgId, String userId) throws Exception {
        Map<String, Object> map = null;
        if (evList == null || evList.size() == 0) {
            map = new HashMap<String, Object>();
            map.put("state", RespCodeEnum.RESP_CODE_ENUM_false.code());
            map.put("msg", "Excel文件内容异常!");
            return map;
        }
        Map<String, Employee> evMap = new HashMap<String, Employee>();
        List<String> repeatOrgList = new ArrayList<String>();//excel重复用户
        List<Employee> cEvList = new ArrayList<Employee>();
        for (Employee ev : evList) {//处理excel中重复数据
            String loginId = ev.getEmail() != null ? ev.getEmail().replace("@petrochina.com.cn", "") : ev.getEmail();
            Employee evParam = evMap.get(loginId);
            if (evParam != null) {
                repeatOrgList.add("重复用户:" + ev.getOrgId() + "=" + ev.getEmail());
                continue;
            }
            if (StringUtils.isNotEmpty(ev.getEmail())) {
                ev.setEmail(null);
                ev.setLoginId(loginId);
            } else {
                ev.setLoginId(ev.getEmail());
            }
            evMap.put(loginId, ev);
        }
        cEvList.addAll(evMap.values());
        EmployeeVo param = new EmployeeVo();
        param.setOrgId(orgId);
        List<EmployeeVo> paramEvList = employeeMapper.selectParamList(param);//查询数据库中数据
        if (paramEvList == null) {
            paramEvList = new ArrayList<EmployeeVo>();
        }
        List<Organization> orgList = organizationService.selectOrgListByEmployee(orgId, OrganizationLevel.ORG_LEVEL_WELL.getCode(), OrganizationLevel.ORG_LEVEL_BRANCH.getCode());
        List<String> repulseOrgList = new ArrayList<String>();//组织不存在打回
        List<Employee> addList = new ArrayList<Employee>();
        List<Employee> updateList = new ArrayList<Employee>();
        List<Department> depList = departmentService.selectDeptByOrgId(orgId);
        Date date = new Date();
        List<String> existenceOrgList = new ArrayList<String>();//表重复用户
        for (Employee ev : cEvList) {
            String employeeId = userComparison(ev.getLoginId(), paramEvList.iterator());//处理数据库中表重复数据
            ev.setModifierId(userId);
            ev.setModifyTime(date);
            if (employeeId != null) {
                existenceOrgList.add("用户已存在:" + ev.getOrgId() + "=" + ev.getLoginId());
                if (StringUtils.isNotEmpty(ev.getWorkNumber())) {
                    ev.setEmployeeId(employeeId);
                    updateList.add(ev);
                }
                continue;
            }
            if (StringUtils.isNotEmpty(ev.getDepId())) {//部门
                Department dep = depComparison(ev.getDepId(), depList);
                if (dep != null && StringUtils.isNotEmpty(dep.getDepId()) && StringUtils.isNotEmpty(dep.getParentOrgId())) {
                    ev.setDepId(dep.getDepId());
                    ev.setOrgId(dep.getParentOrgId());
                } else {
                    String str = "所属部门不存在:" + ev.getOrgId() + "=" + ev.getLoginId();
                    repulseOrgList.add(str);
                    continue;
                }
            } else if (StringUtils.isNotEmpty(ev.getOrgId())) {//组织
                String orgIds = orgComparison(ev.getOrgId(), orgList);
                if (StringUtils.isNotEmpty(orgIds)) {
                    ev.setOrgId(orgIds);
                } else {
                    String str = "所属场站不存在:" + ev.getOrgId() + "=" + ev.getLoginId();
                    repulseOrgList.add(str);
                    continue;
                }
            } else {
                String str = "所属组织、部门不存在:" + ev.getOrgId() + "=" + ev.getLoginId();
                repulseOrgList.add(str);
                continue;
            }
            ev.setCreatorId(userId);
            ev.setCreateTime(date);
            ev.setModifierId(userId);
            ev.setModifyTime(date);
            ev.setStatus((short) 0);
            ev.setPassword("123456");
            ev.setSex((short) 0);
            ev.setEmployeeId(UniqueUtil.uuid());
            addList.add(ev);
        }
        StringBuffer sb = new StringBuffer("数据异常返回:" + JSON.toJSONString(repulseOrgList));
        sb.append("。 已存在用户:" + JSON.toJSONString(existenceOrgList));
        sb.append("。 Excel中重复用户:" + JSON.toJSONString(repeatOrgList));
        map = new HashMap<String, Object>();
        if (updateList.size() > 0) {
            employeeMapper.updateList(updateList);
            sb.append("。 修改成功数据总数:" + updateList.size());
        }
        if (addList.size() > 0) {
            int num = employeeMapper.insertList(addList);
            if (num > 0) {
                map.put("state", RespCodeEnum.RESP_CODE_ENUM_true.code());
                map.put("msg", "上传成功!" + sb.toString());
            } else {
                map.put("state", RespCodeEnum.RESP_CODE_ENUM_false.code());
                map.put("msg", "保存失败!" + sb.toString());
            }
        } else {
            map.put("state", RespCodeEnum.RESP_CODE_ENUM_false.code());
            map.put("msg", "上传失败!" + sb.toString());
        }
        return map;
    }

    //判断用户是否存在表中
    private String userComparison(String loginId, Iterator<EmployeeVo> it) {
        while (it.hasNext()) {
            Employee ev = it.next();
            if (ev.getLoginId() != null && ev.getLoginId().equalsIgnoreCase(loginId)) {
                it.remove();
                return ev.getEmployeeId();
            }
        }
        return null;
    }

    //处理部门
    private Department depComparison(String depName, List<Department> depList) {
        for (Department dep : depList) {
            if (dep.getDepName().equals(depName)) {
                return dep;
            }
        }
        return null;
    }

    //处理组织
    private String orgComparison(String orgName, List<Organization> orgList) {
        for (Organization org : orgList) {
            if (org.getOrgName().equals(orgName)) {
                return org.getOrgId();
            }
        }
        return null;
    }

    /**
     * 查询导入组织树形
     *
     * @param orgId   登录人员所属组织
     * @param pOrgId  树形上级组织
     * @param keyword 条件搜索
     * @return
     * @throws Exception
     */
    public List<Ztree> initExcelTree(String orgId, String pOrgId, String keyword) throws Exception {
        return organizationService.initTree(orgId, pOrgId, keyword, OrganizationLevel.ORG_LEVEL_STATION.getCode());
    }

    /**
     * 验证工卡ID是否重复
     *
     * @param employeeId
     * @param cardId
     * @return
     */
    @Override
    public boolean isCard(String employeeId, String cardId) {
        Employee employee = new Employee();
        employee.setEmployeeId(employeeId);
        employee.setCardId(cardId);
        int num = employeeMapper.isExis(employee);
        return num > 0 ? false : true;
    }

    /**
     * 上传人员头像图片信息
     *
     * @param uploadFiles 图片信息
     * @param orgId       组织ID
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Map<String, Object> uploadImg(String uploadFiles, String orgId) {
        Map<String, Object> map = null;
        List<File> listFiles = JSON.parseArray(uploadFiles, File.class);
        EmployeeVo param = new EmployeeVo();
        param.setOrgId(orgId);
        List<EmployeeVo> paramEvList = employeeMapper.selectParamList(param);//查询数据库中数据
        if (paramEvList == null || paramEvList.size() == 0) {
            map = new HashMap<String, Object>();
            map.put("state", RespCodeEnum.RESP_CODE_ENUM_false.code());
            map.put("msg", "该组织下没有人员存在!!");
            return map;
        }
        List<String> noExistenceList = new ArrayList<String>();//人员不存在
        List<String> imgList = new ArrayList<String>();//人员头像图片异常
        List<String> deleteList = new ArrayList<String>();//删除原有头像图片ID集合
        List<File> newList = new ArrayList<>();
        for (File file : listFiles) {
            System.out.println(file.getFileName().split("."));
            String[] name = file.getFileName() != null ? file.getFileName().split("\\.") : null;
            if (name == null || name.length == 0) {
                imgList.add(file.getFileName());
                continue;
            }
            String userId = userNameComparison(name[0], paramEvList.iterator());
            if (StringUtils.isEmpty(userId)) {
                noExistenceList.add(file.getFileName());
                continue;
            }
            file.setFileId(UniqueUtil.uuid());
            //设置业务数据id
            file.setBusinessId(userId);
            file.setFileType((short) FileTypeUtil.getCode(file.getExt()));
            newList.add(file);
            deleteList.add(userId);
        }
        StringBuffer sb = new StringBuffer("头像图片异常:" + JSON.toJSONString(imgList));
        sb.append("。 人员不存在:" + JSON.toJSONString(noExistenceList));
        map = new HashMap<String, Object>();
        if (newList.size() > 0) {
            fileService.deleteListString(deleteList);
            try {
                int num = fileService.insertList(newList);
                if (num > 0) {
                    map.put("state", RespCodeEnum.RESP_CODE_ENUM_true.code());
                    map.put("msg", "上传成功!" + sb.toString());
                } else {
                    map.put("state", RespCodeEnum.RESP_CODE_ENUM_false.code());
                    map.put("msg", "保存失败!" + sb.toString());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return map;
        } else {
            map = new HashMap<String, Object>();
            map.put("state", RespCodeEnum.RESP_CODE_ENUM_false.code());
            map.put("msg", "上传失败! " + sb.toString());
            return map;
        }
    }

    //判断用户是否存在表中
    private String userNameComparison(String name, Iterator<EmployeeVo> it) {
        while (it.hasNext()) {
            Employee ev = it.next();
            if (ev.getLoginId() != null && ev.getName().equals(name)) {
                it.remove();
                return ev.getEmployeeId();
            }
        }
        return null;
    }

    /**
     * @param orgId 作业区机构id，查询作业区下 所有的部门负责人
     * @return
     * @throws Exception
     */
    @Override
    public List<Ztree> queryDeptManagerList(String orgId) throws Exception {
        List<Ztree> ztreeList = new ArrayList<>();
        logger.info("queryDeptManagerList---->start:" + orgId);
        /**
         * 1、查询下面所有的人员
         * 2、查询下面所有的角色
         * 3、查询下面所有的部门
         * 4、形成组织机构 ，如果没有则返回空
         */

        /**
         * 1 、查询下面所有的人员
         */
        List<EmployeeVo> employeeList = employeeMapper.queryDeptManagerList(orgId);
        // 是否查询得到人，如果查询不到人
        if (employeeList != null && employeeList.size() > 0) {
            // 人员信息组装
            for (EmployeeVo employee : employeeList) {
                Ztree empZ = new Ztree();
                empZ.setId(employee.getEmployeeId());
                empZ.setName(employee.getName());
                empZ.setIsParent(false);
                empZ.setOpen(true);
                empZ.setpId(employee.getRoleId());
                empZ.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                ztreeList.add(empZ);
            }
            /**
             *  2 、查询下面所有的角色
             *  转成角色
             */
            List<Roles> rolesList = rolesService.queryDeptManagerList(orgId);
            if (rolesList != null && rolesList.size() > 0) {
                for (Roles rs : rolesList) {
                    Ztree rsz = new Ztree();
                    rsz.setId(rs.getRoleId());
                    rsz.setName(rs.getRoleName());
                    rsz.setIsParent(false);
                    rsz.setOpen(true);
                    rsz.setpId(rs.getOrgId());
                    rsz.setIconSkin(TreeIconSkin.ICON_ROLES.getDesc());
                    ztreeList.add(rsz);
                }
            }
            /**
             *  3 、查询下面所有的部门
             */
            List<Department> departmentList = departmentMapper.selectDeptByOrgId(orgId);
            if (departmentList != null && departmentList.size() > 0) {
                for (Department dept : departmentList) {
                    Ztree deptZ = new Ztree();
                    deptZ.setId(dept.getDepId());
                    deptZ.setName(dept.getDepName());
                    deptZ.setIsParent(false);
                    deptZ.setOpen(true);
                    deptZ.setpId(dept.getParentOrgId());
                    deptZ.setIconSkin(TreeIconSkin.ICON_DEPT.getDesc());
                    ztreeList.add(deptZ);
                }
            }
        }

        Organization organization = organizationService.selectOrgByOrgId(orgId);
        if (organization != null) {
            Ztree orgz = new Ztree();
            orgz.setId(organization.getOrgId());
            orgz.setName(organization.getOrgName());
            orgz.setOpen(true);
            orgz.setIsParent(false);
            orgz.setpId(organization.getParentOrgId());
            orgz.setIconSkin(TreeIconSkin.ICON_OA.getDesc());
            ztreeList.add(orgz);
        }
        logger.info("queryDeptManagerList---->end:" + orgId);
        return ztreeList;
    }


    /**
     * @return
     * @throws Exception
     */
    public List<Ztree> queryDeptManagerListByEmployeeVo(Employee employee) throws Exception {
        List<Ztree> ztreeList = new ArrayList<>();
        List<Organization> organizationList = organizationService.getOrganizationList(employee);
        if (organizationList != null && organizationList.size() > 0) {
            for (Organization org : organizationList) {
                ztreeList.addAll(queryDeptManagerList(org.getOrgId()));
            }
        }
        return ztreeList;
    }

    /**
     * @param deptId 传部门id, 查询部门下所有的人员信息 （多个部门，逗号隔开 ）
     */
    @Override
    public List<Ztree> queryDeptList(String deptId) throws Exception {
        Map<String, Organization> orgMap = new HashMap<>();
        List<Ztree> ztreesList = new ArrayList<>();
        // 判断是否存在部门id
        if (StringUtils.isNotEmpty(deptId)) {
            String[] deptIdArry = deptId.split(",");
            for (int i = 0; i < deptIdArry.length; i++) {
                Department dept = departmentService.findDeptById(deptIdArry[i]);
                if (dept != null) {
                    Ztree deptZtree = new Ztree();
                    deptZtree.setId(dept.getDepId());
                    deptZtree.setName(dept.getDepName());
                    deptZtree.setpId(dept.getParentOrgId());
                    deptZtree.setIsParent(false);
                    deptZtree.setOpen(true);
                    deptZtree.setIconSkin(TreeIconSkin.ICON_DEPT.getDesc());
                    ztreesList.add(deptZtree);
                    if (StringUtils.isNotEmpty(dept.getParentOrgId())) {
                        Organization organization = organizationService.selectOrgByOrgId(dept.getParentOrgId());
                        orgMap.put(dept.getParentOrgId(), organization);
                    }
                }
                Employee employee = new Employee();
                employee.setDepId(deptIdArry[i]);
                List<Employee> employeeVoList = employeeMapper.selectListEmploye(employee);
                // 判断当前部门下是否有人
                if (employeeVoList != null && employeeVoList.size() > 0) {
                    for (Employee employeeVo : employeeVoList) {
                        Ztree ztree = new Ztree();
                        ztree.setId(employeeVo.getEmployeeId());
                        ztree.setName(employeeVo.getName());
                        if (StringUtils.isNotEmpty(employeeVo.getDepId())) {
                            ztree.setpId(employeeVo.getDepId());
                        } else {
                            ztree.setpId(employeeVo.getOrgId());
                        }
                        ztree.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                        ztree.setOpen(false);
                        ztree.setIsParent(false);
                        ztreesList.add(ztree);
                    }
                }
            }
        }

        // 判断是否有作业区
        if (orgMap != null && orgMap.size() > 0) {
            for (Organization organization : orgMap.values()) {
                Ztree orgZ = new Ztree();
                orgZ.setId(organization.getOrgId());
                orgZ.setName(organization.getOrgName());
                orgZ.setpId(organization.getParentOrgId());
                orgZ.setIsParent(false);
                orgZ.setOpen(true);
                orgZ.setIconSkin(organizationService.offsetIconSkin(organization));
                ztreesList.add(orgZ);
            }
        }
        return ztreesList;
    }

    /**
     * 作业区人员分布统计报表页面查询
     *
     * @param orgId
     * @return
     */
    @Override
    public Map<String, Object> findReportFormList(String orgId) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (StringUtils.isEmpty(orgId)) {
            map.put("rows", null);
            return map;
        }
        List<Organization> orgList = organizationService.selectOrgByOrgPId(orgId);
        if (orgList == null) {
            map.put("rows", null);
            return map;
        }
        Organization o = new Organization();
        o.setOrgId(orgId);
        o.setOrgLevelId(OrganizationLevel.ORG_LEVEL_WELL.getCode());
        List<Organization> orgItemList = organizationService.selectByOrgItem(o);
        if (orgItemList == null) {
            orgList = new ArrayList<Organization>();
        }
        Organization organization = organizationService.selectOrgByOrgId(orgId);
        if (organization == null) {
            organization = new Organization();
        }

        Organization org2 = null;
        if (orgId.equals(organization.getOrgLevelId())) {
            //分公司
            organization.setOrgLevelId("0");
        } else {
            //气矿， 作业区
            if (!organization.getParentOrgId().equals("#")) {
                org2 = organizationService.selectOrgByOrgId(organization.getParentOrgId());
                organization.setOrgLevelId(org2 != null ? org2.getOrgLevelId() : "0");
                if (org2 == null) {
                    map.put("rows", null);
                    return map;
                }
            }
        }
        List<EmployeeVo> list = new ArrayList<EmployeeVo>();
        int orgLevelId = !organization.getOrgLevelId().equals("#") ? Integer.parseInt(organization.getOrgLevelId()) : 0;
        EmployeeVo ev = null;
        int count = 0;
        if (orgLevelId > 0) {
            List<DepartmentVO> depList = departmentService.selectByPOId(orgId);
            if (depList != null) {
                if (orgLevelId == 1) {
                    //气矿
                    for (DepartmentVO dep : depList) {
                        ev = new EmployeeVo();
                        ev.setDepId(dep.getDepId());
                        ev.setOrgName(dep.getDepName());
                        List<EmployeeVo> emplList = employeeMapper.findDepReportFormList(ev);
                        if (emplList.size() <= 0) {
                            continue;
                        }
                        int sizeCount = 0;
                        sizeCount = emplList.size();
                        ev.setWorkNumber(sizeCount + "");//人数数量
                        count += sizeCount;
                        ev.setShowOrgName(organization.getOrgName());
                        ev.setPostName(organization.getOrgLevelId());
                        ev.setRoleId(organization.getParentOrgId());
                        list.add(ev);
                    }
                } else {
                    //分公司， 作业区
                    for (DepartmentVO dep : depList) {
                        ev = new EmployeeVo();
                        ev.setDepId(dep.getDepId());
                        ev.setOrgName(dep.getDepName());
                        int sizeCount = 0;
                        if (2 > orgLevelId) {
                            //气矿，分公司
                            List<EmployeeVo> emplList = employeeMapper.findDepReportFormList(ev);
                            sizeCount = emplList.size();
                            ev.setWorkNumber(sizeCount + "");//人数数量
                        } else {
                            //作业区
                            List<EmployeeVo> emplList = employeeMapper.findDepSexReportFormList(ev);
                            sizeCount = setValue(ev, emplList);
                        }
                        count += sizeCount;
                        ev.setShowOrgName(organization.getOrgName());
                        ev.setPostName(organization.getOrgLevelId());
                        ev.setRoleId(organization.getParentOrgId());
                        list.add(ev);
                    }
                }
            }
        }
        for (Organization org : orgList) {
            ev = new EmployeeVo();
            ev.setOrgId(org.getOrgId());
            int sizeCount = 0;
            if (2 > orgLevelId) {
                //气矿，分公司
                List<EmployeeVo> emplList = employeeMapper.selectParamList(ev);
                sizeCount = emplList.size();
                ev.setWorkNumber(sizeCount + "");//人数数量
                ev.setIsSelect(isItem(org.getOrgId(), orgItemList.iterator()));
            } else {
                //作业区
                List<EmployeeVo> emplList = employeeMapper.findOrgSexReportFormList(ev);
                sizeCount = setValue(ev, emplList);
            }
            count += sizeCount;
            ev.setOrgName(org.getOrgName());
            ev.setShowOrgName(organization.getOrgName());
            ev.setPostName(organization.getOrgLevelId());
            ev.setRoleId(organization.getParentOrgId());
            list.add(ev);
        }
        if (2 > orgLevelId) {
            //气矿，分公司
            for (EmployeeVo e : list) {
                e.setCardId(count + "");//总人数数量
            }
        } else {
            //作业区
            int female = 0;//女
            int male = 0;//男
            for (EmployeeVo e : list) {
                if (StringUtils.isNotEmpty(e.getWorkNumber())) {
                    female += Integer.parseInt(e.getWorkNumber());
                }
                if (StringUtils.isNotEmpty(e.getPortraitCode())) {
                    male += Integer.parseInt(e.getPortraitCode());
                }
            }
            ev = new EmployeeVo();
            ev.setShowOrgName("合计");
            ev.setRoleId(organization.getParentOrgId());
            ev.setWorkNumber(female + "");//女性数量
            ev.setPortraitCode(male + "");//男性数量
            ev.setCardId(count + "");//合计
            list.add(ev);
        }
        map.put("rows", list);
        return map;
    }

    /**
     * 赋值人数
     *
     * @param ev
     * @param emplList
     */
    private int setValue(EmployeeVo ev, List<EmployeeVo> emplList) {
        ev.setWorkNumber(sexCount(1, emplList.iterator()));//女性数量
        ev.setPortraitCode(sexCount(0, emplList.iterator()));//男性数量
        int num = 0;
        if (ev.getWorkNumber() != null && ev.getPortraitCode() != null) {
            num = (Integer.parseInt(ev.getWorkNumber()) + Integer.parseInt(ev.getPortraitCode()));
            ev.setCardId(num + "");//总人数数量
        } else if (ev.getWorkNumber() != null) {
            num = Integer.parseInt(ev.getWorkNumber());
            ev.setCardId(ev.getWorkNumber());//总人数数量
        } else if (ev.getPortraitCode() != null) {
            num = Integer.parseInt(ev.getPortraitCode());
            ev.setCardId(ev.getPortraitCode());//总人数数量
        }
        return num;
    }

    /**
     * 判断对应orgId是否存在子项
     *
     * @param orgId
     * @param it
     * @return
     */
    private String isItem(String orgId, Iterator<Organization> it) {
        while (it.hasNext()) {
            Organization param = it.next();
            if (orgId.equals(param.getParentOrgId())) {
                it.remove();
                return "1";
            }
        }
        return "0";
    }

    /**
     * 判断对应orgId是否存在子项
     *
     * @param sex
     * @param it
     * @return
     */
    private String sexCount(int sex, Iterator<EmployeeVo> it) {
        while (it.hasNext()) {
            EmployeeVo param = it.next();
            if (param.getSex() == sex || param.getSex().equals(sex)) {
                return param.getStatus().toString();
            }
        }
        return null;
    }
    /**
     * 根据当前人所属组织机构和菜单id，查询作业区下所有拥有该菜单的用户
     * @param orgId
     * @param menuId
     * @Author chenpeng
     * @return
     */
    public List<Employee> queryOwnMenuConditionByOrgId(String orgId, String menuId){
        Map<String,String> paramMap = new HashMap<>();
        paramMap.put("orgId",orgId);
        paramMap.put("menuId",menuId);
        return employeeMapper.queryOwnMenuConditionByOrgId(paramMap);
    }

    /**
     * @param employeeVo 当前登录人
     * @return
     * @throws Exception
     */
    @Override
    public List<Ztree> queryEmployeeList(EmployeeVo employeeVo) throws Exception {
        List<Ztree> ztreeList = new ArrayList<>();
        Employee param = new Employee();
        // 存在部门查询部门下所有的人 ， 如果没有部门 查询组织机构下所有的人
        if(StringUtils.isNotEmpty(employeeVo.getDepId())){
                param.setDepId(employeeVo.getDepId());
                DepartmentVO department = departmentMapper.selectByDeptId(employeeVo.getDepId());
                if(department != null && StringUtils.isNotEmpty(department.getDepId())){
                        Ztree ztree =  new Ztree();
                        ztree.setId(department.getDepId());
                        ztree.setName(department.getDepName());
                        ztree.setpId(department.getParentOrgId());
                        ztree.setIsParent(false);
                        ztree.setOpen(true);
                        ztree.setIconSkin(TreeIconSkin.ICON_DEPT.getDesc());
                        ztreeList.add(ztree); // 加载部门节点
                }
        }
        if(StringUtils.isNotEmpty(employeeVo.getOrgId())){
            param.setOrgId(employeeVo.getOrgId());
            Organization organization = organizationMapper.selectByPrimaryKey(employeeVo.getOrgId());
            if(organization != null && StringUtils.isNotEmpty(organization.getOrgId())){
                Ztree ztree =  new Ztree();
                ztree.setId(organization.getOrgId());
                ztree.setName(organization.getOrgName());
                ztree.setpId("#");
                ztree.setIconSkin(organizationService.offsetIconSkin(organization));
                ztree.setIsParent(false);
                ztree.setOpen(true);
                ztreeList.add(ztree); // 加载组织节点
            }
        }
        List<Employee> employeeList = employeeMapper.selectListEmploye(param);
        if(employeeList != null && employeeList.size() > 0){
                for(Employee employee : employeeList){
                    Ztree ztree = new Ztree();
                    ztree.setId(employee.getEmployeeId());
                    ztree.setName(employee.getName());
                    if(StringUtils.isNotEmpty(employee.getDepId())){
                        ztree.setpId(employee.getDepId());
                    }else{
                        ztree.setpId(employee.getOrgId());
                    }
                    ztree.setIconSkin(TreeIconSkin.ICON_PEOPLE.getDesc());
                    ztree.setIsParent(false);
                    ztree.setOpen(true);
                    ztreeList.add(ztree); // 加载组织节点
                }
        }

        return ztreeList ;
    }

    /**
     * @param employeeVo 根据人员信息查询当前人员同组织机构的人员信息
     * @return
     * @throws Exception
     */
    @Override
    public List<Employee> queryOrgEmployeeList(EmployeeVo employeeVo) throws Exception {
        Employee param = new Employee();
        // 根据人员信息查询当前人员同组织机构的人员信息
        if(StringUtils.isNotEmpty(employeeVo.getOrgId())){
            param.setOrgId(employeeVo.getOrgId());
        }
        // 根据人员信息查询当前人员同组织机构的人员信息
        if(StringUtils.isNotEmpty(employeeVo.getDepId())){
            param.setDepId(employeeVo.getDepId());
        }
        return  employeeMapper.selectListEmploye(param);
    }

    /**
     * 查询作业区下所有角色名称为XXX的人员
     * Author:cp
     * @param areaOrgId
     * @param roleName
     * @return
     */
    @Override
    public List<Employee> queryEmployeeByAreaOrgIdAndRoleName(String areaOrgId,String roleName){
        Map<String,String> queryCondition = new HashMap<>();
        queryCondition.put("orgId",areaOrgId);
        queryCondition.put("roleName",roleName);
        return employeeMapper.queryEmployeeByAreaOrgIdAndRoleName(queryCondition);
    }


    /**
     * 修改人员信息
     *
     * @param record
     * @return
     */
    @Override
    public int update(Employee record) {
        record.setModifyTime(new Date());
        return employeeMapper.updateByPrimaryKeySelective(record);
    }
}
